﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Engine.Gameplay.GameWorld;

namespace Engine.Game
{
    public class EngineGame : Microsoft.Xna.Framework.Game
    {
        #region Fields
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Engine engine;
        #endregion // Fields


        #region Properties

        IWorld World { get; set; }
        #endregion // Properties


        #region Constructors
        public EngineGame(Engine engine)
        {
            this.engine = engine;
            graphics = new GraphicsDeviceManager(this);
            graphics.IsFullScreen = false;
            graphics.PreferredBackBufferHeight = 1600;
            graphics.PreferredBackBufferWidth = 900;
            Content.RootDirectory = "Content";
        }
        #endregion // Constructors


        #region Methods
        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            World = new World(engine.RenderingSystem);
            engine.GameManager.World = World;
            engine.GameManager.Content = this.Content;
            engine.GameManager.LoadContent();
        }

        protected override void UnloadContent() { }

        protected override void Update(GameTime gameTime)
        {
            if (engine.GameManager.DoExit)
                this.Exit();

            engine.InputHandlerSystem.ProcessInput();
            engine.GameManager.Update(gameTime);
            World.Update(gameTime);
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            World.Draw(gameTime);
            base.Draw(gameTime);
        }
        #endregion // Methods
    }
}
